/*
 * Copyright  bocmbci
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { CallbackContext } from './CallbackContext';
import { CordovaInterface } from './CordovaInterface';
import { CordovaWebViewService } from './CordovaWebViewService';

export class CordovaPlugin{
  protected  cordovaWebViewService: CordovaWebViewService
  protected  cordovaInterface: CordovaInterface
  protected  serviceName: string;

  constructor( _cordovaService: CordovaWebViewService, _cordovaInterface: CordovaInterface) {
    this.cordovaWebViewService = _cordovaService;
    this.cordovaInterface = _cordovaInterface;
  }

  privateInitialize(serviceName: string, cordovaInterface: CordovaInterface, cordovaWebViewService: CordovaWebViewService){
    this.serviceName = serviceName;
    this.cordovaWebViewService = cordovaWebViewService;
    this.cordovaInterface = cordovaInterface;
  }

  public getServiceName(): string {
    return this.serviceName;
  }

  execute(action: string, args: string, callbackContext: CallbackContext): boolean{
    return false;
  }

  /**
   * Called when the system is about to start resuming a previous ability.
   *
   * @param multitasking		Flag indicating if multitasking is turned on for app
   */
  onPause(multitasking: boolean): void{
  }

  /**
   * Called when the ability will start interacting with the user.
   *
   * @param multitasking		Flag indicating if multitasking is turned on for app
   */
  onResume(multitasking: boolean): void{
  }
  
  /**
   * Called when the ability is becoming visible to the user.
   */
  onStart() {
  }
  
  /**
   * Called when the ability is no longer visible to the user.
   */
  onStop() {
  }
  
  /**
   * The final call you receive before your ability is destroyed.
   */
  onDestroy() {
  }

  /**
   * Called when a message is sent to plugin.
   *
   * @param id            The message id
   * @param data          The message data
   * @return              Object to stop propagation or null
   */
  onMessage(id: string, data: object): Object{
    return null;
  }

  /**
   * Called when the WebView does a top-level navigation or refreshes.
   *
   * Plugins should stop any long-running processes and clean up internal state.
   *
   * Does nothing by default.
   */
  onReset() {
  }

  shouldAllowRequest(url: string){
    return true;
  }

  shouldAllowNavigation(url: string){
    return true;
  }

  shouldAllowBridgeAccess(url){
    return true;
  }

  shouldOpenExternalUrl(url){
    return true;
  }

  onOverrideUrlLoading(url){
    return false;
  }
}